package com.neuedu.hcp.controller;


import com.neuedu.hcp.entity.*;
import com.neuedu.hcp.service.IPatientService;
import com.neuedu.hcp.service.IRecoveryRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZZD
 * @since 2021-04-26
 */
@RestController
@RequestMapping("/register")
public class RecoveryRegisterController {
    @Autowired
    private IRecoveryRegisterService recoveryRegisterService;

    @Autowired
    private IPatientService patientService;
    /**
     * 分页查询 /register/registerList
     * @param currentPage
     * @param size
     * @param recoveryRegister
     * @return
     */
    @GetMapping("/registerList")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             RecoveryRegister recoveryRegister){
        return recoveryRegisterService.getRegisterByPage(currentPage,size,recoveryRegister);
    }

    /**
     * 插入 /register/insert
     * @param recoveryRegister
     * @return
     */
    @PostMapping("/insert")
    public RespBean insert(@RequestBody RecoveryRegister recoveryRegister){
        if(recoveryRegisterService.insert(recoveryRegister)<=0){
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }

    /**
     * 更新 /register/update
     * @param recoveryRegister
     * @return
     */
    @PostMapping("/update")
    public RespBean update(@RequestBody RecoveryRegister recoveryRegister){
        if(recoveryRegisterService.updateById(recoveryRegister)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除 /register/delete
     * @param patientId
     * @return
     */
    @GetMapping("/delete")
    public RespBean delete(Integer patientId){
        if(recoveryRegisterService.removeById(patientId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }
}
